<template>
	<view class="conter">
		<header-box :title="title"></header-box>
		<view class="text-tab">
			<view class="box">

				<view class="marige-bor"  v-for="(item, index) in textList" :key="index">
					<view class="diso-flex">
						<view class="left-box">
							<view class="left-box-image" @tap="skip(item.id)">
								<image class="w220 h220 r10" :src="img + item.image" mode=""></image>
							</view>
							<view class="" style="line-height: 60rpx;">
								<view class="">
									{{item.name}}
								</view>
								<view class="">
									数量: &nbsp{{item.num}}
								</view>
								<!-- <view class="" @click="removeGoodsList(item)">

								</view> -->
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<block v-if="stock == '2'">
			<view class="total1">
				<button v-if="s_status == 0" type="default"
					class="total1-btn cu-btn ww90 h80 lh80 "
					style="background-color: #656CE6; 
					color: #FFFFFF;"
					@tap="addShow = true">
				归还
				</button>
			</view>
		</block>
		
		
		
		<view class="flex-box total">
			<view class="">
				合计：
			</view>
			<view class="">
				{{leng}} 个
			</view>
		</view>
		
		<!-- putStock -->
		<u-modal v-model="addShow" :show-cancel-button="true" @confirm="putStock" :content="content"></u-modal>
		
		<!-- 底部弹层 -->
		<u-popup v-model="redactShow" mode="bottom" width="100%" height="330rpx" border-radius="40">
			<view class="padd-text" v-for="(item, index) in list" :key="index" @click="elect(item, index)">
				<text :class="[index == tabText ? 'color-text' : 'none-color']">{{item.name}}</text>
			</view>
		</u-popup>
		
		
		<!-- 确定删除 -->
		<u-popup v-model="popupShow1" mode="center" width="70%" height="180rpx" border-radius="10">
			<view class="input-text">
				删除-<text style="color: #f00;">{{removeName}}</text>
			</view>
			<view class="text-select">
				<view class="" @click="popupShow1 = false">
					取消
				</view>
				<view class="" @click="removeGoods">
					确定
				</view>
			</view>
		</u-popup>
		
		
	</view>
</template>

<script>
	import headerBox from '../../components/header/header.vue'

	export default {
		components: {
			headerBox
		},
		data() {
			return {
				addShow: false,
				title: '',
				textList: [],
				addUrl: '',
				tabText: 0,
				img: this.$images,
				redactShow: false,
				popupShow1: false,
				list: [{
					name: '编辑',
					show: true,
					url: ''
				},{
					name: '删除',
					show: true
				},{
					name: '取消',
					show: false
				}],
				total: '',
				// page: 1,
				// rows: 10,
				id: '',
				value: '',
				removeName: '',
				totalPage: '',
				classId: '',
				leng: '',
				stock: '',
				s_status: '',
				content: '确定归还?',
			}
		},
		onLoad(e) {
			this.classId = e.infoId
			console.log(e.s_status)
			this.s_status = e.s_status
			this.stock = e.stock
			this.stockList()
		},
		onShow() {
			// this.stockList()
		},
		// 下拉触底
		onReachBottom(e) {
			var pages = this.page++
			if (pages > this.totalPage) return
			this.stockList()
			console.log('触底l')
		},
		methods: {
			
			// 获取列表
			async stockList() {
				if (this.stock == '1') {
					this.title = '入库单详情'
					const res = await this.$u.post("api/Invoic/buy_order_find_info",{
						orderbm: this.classId,
					});
					// this.textList = [...this.textList,...res.list]
					this.textList = res.data
					this.leng = this.textList.length
					console.log('获取列表', this.$images + this.textList[0].image)
				}
				if(this.stock == '2') {
					this.title = '出库单详情'
					const res = await this.$u.post("api/Invoic/sales_order_info",{
						orderbm: this.classId,
					});
					// this.textList = [...this.textList,...res.list]
					this.textList = res.data
					this.leng = this.textList.length
					console.log('获取列表', this.textList.length)
				}
				
			},
			
			
			// 删除商品
			async removeGoods() {
				const res = await this.$u.post("api/jinxiao.Goods/delete?id=" + this.id);
				if(res.code !== 1) return this.$tools.msg(res.msg)
				this.redactShow = false
				this.popupShow1 = false
				this.stockList()
				this.$tools.msg(res.msg)
			},
			
			
			// 点击弹出底部弹框
			removeGoodsList(item) {
				this.redactShow = true
				this.id = item.id
				this.removeName = item.name
				console.log(item.id)
			},
			
			
			
			skip(id) {
				console.log(id)
				// uni.navigateTo({
				// 	url: '/pages/shopping/shoppingInfo?id=' + id
				// });
			},
			
			elect(item, index) {
				console.log(index)
				this.tabText = index
				this.redactShow = item.show
				if (index == 0) {
					// 跳转到编辑页面
					this.redactShow = false
					
					uni.navigateTo({
						url: '/pages/shopping/addShopping?item=' + 1
					})
					
					
				} else if (index == 1) {
					
					this.popupShow1 = true
					// 调用删除事件
				}
			},
			
			async putStock() {
				const res = await this.$u.post("api/Invoic/sales_order_back?orderbm=" + this.classId);
				console.log(res)
				if (res.code == 1) {
					this.$tools.msg(res.msg)
					
					setTimeout( function() {
						uni.navigateBack({
							delta: 1
						})
					},1000)
				} else {
					this.$tools.msg(res.msg)
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.conter {
		width: 100%;
		height: 100%;
		padding-bottom: 120rpx;
		position: relative;
		background-color: #EEEEEE;

		image {
			width: 100%;
			height: 100%;
		}

		.text-tab {
			width: 100%;
			padding: 30rpx;
			padding-bottom: 0;
			background-color: #EEEEEE;


			.box {
				width: 98%;
				margin: 0 auto;
				background-color: #FFFFFF;
				border-radius: 10rpx;
			}

			.marige-bor {
				width: 90%;
				margin: 0 auto;
				color: #333333;
				display: flex;
				font-size: 28rpx;
				padding: 20rpx 0;
				align-items: center;
				// border-bottom: 1rpx solid #F0F0F0;
				justify-content: space-between;

				.diso-flex {
					width: 100%;
					// height: 170rpx;
					padding-bottom: 20rpx;
					border-bottom: 1rpx solid #EEEEEE;
					
					
					.left-box {
						display: flex;
						align-items: center;
						
						.left-box-image {
							width: 220rpx;
							height: 220rpx;
							margin-right: 22rpx;
							border-radius: 10rpx;
						}
						
						.box-border {
							width: 100%;
							height: 100%;
							line-height: 60rpx;
							align-items: center;
						}
					}
					
					.right-box {
						width: 100%;
						height: 158rpx;
						display: flex;
						align-items: center;
						justify-content: space-between;
						border-bottom: 1rpx solid #F0F0F0;
					}
					
					// .right-box:last-child {
					// 	border-bottom: 0;
					// }
				}

				.conter-image {
					width: 22rpx;
					height: 36rpx;
				}
			}
			
			
		}

		// 加号
		.add {
			position: fixed;
			bottom: 200rpx;
			right: 40rpx;
			width: 160rpx;
			height: 160rpx;
			text-align: center;
			line-height: 100rpx;
			border-radius: 50%;
			font-size: 100rpx;
			color: #FFFFFF;
		}

		.total {
			width: 100%;
			position: fixed;
			bottom: 0;
			left: 0;
			height: 100rpx;
			padding: 0 60rpx 0 30rpx;
			background-color: #FFFFFF;
		}
		
		.total1 {
			position: fixed;
			width: 100%;
			bottom: 123rpx;
			left: 0;
			height: 100rpx;
			text-align: center;
			// padding: 0 60rpx 0 30rpx;
			display: flex;
			justify-content: center;
			
		}
		
		.total1-btn {
			position: fixed;
			bottom: 123rpx;
			height: 100rpx;
			text-align: center;
			padding: 0 60rpx 0 30rpx;
			background-color: #FFFFFF;
		}
		
		
		.padd-text {
			width: 80%;
			height: 106rpx;
			line-height: 106rpx;
			text-align: center;
			font-size: 28rpx;
			color: #333;
			border-bottom: 1rpx solid #EEEEEE;
			margin: 0 auto;
		}
		
		.color-text {
			color: #7278EC;
		}
		
		.none-color {
			color: #000;
		}
		
		
		
		
		.input-text {
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			margin-top: 10rpx;
		}
		
		.input-val {
			width: 80%;
			height: 60rpx;
			line-height: 60rpx;
			margin: 0 auto 30rpx;
		}
		
		.text-select {
			width: 90%;
			margin: 0 auto;
			border-top: 1rpx solid #F0F0F0;
			display: flex;
			color: #AFB3F1;
			// padding-top: 20rpx;
			justify-content: space-around;
			
			view {
				width: 50%;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				border-right: 1rpx solid #F0F0F0;
			}
			
			view:last-child {
				border-right: 0;
			}
		}

	}
</style>
